package Pokero;
public class Scheme {
        
        public static int[] getValue(Card[] Hand)
        {
                int[] value = new int [5];
                for(int i = 0; i<5; i++)
                {
                        if(Hand[i].rank == "2")
                        {
                                value[i] = 2;
                        }
                        else if(Hand[i].rank == "3")
                        {
                                value[i] = 3;
                        }
                        else if(Hand[i].rank == "4")
                        {
                                value[i] = 4;
                        }
                        else if(Hand[i].rank == "5")
                        {
                                value[i] = 5;
                        }
                        else if(Hand[i].rank == "6")
                        {
                                value[i] = 6;
                        }
                        else if(Hand[i].rank == "7")
                        {
                                value[i] = 7;
                        }
                        else if(Hand[i].rank == "8")
                        {
                                value[i] = 8;
                        }
                        else if(Hand[i].rank == "9")
                        {
                                value[i] = 9;
                        }
                        else if(Hand[i].rank == "10")
                        {
                                value[i] = 10;
                        }
                        else if(Hand[i].rank == "Jack")
                        {
                                value[i] = 11;
                        }
                        else if(Hand[i].rank == "Quinn")
                        {
                                value[i] = 12;
                        }
                        else if(Hand[i].rank == "King")
                        {
                                value[i] = 13;
                        }
                        else if(Hand[i].rank == "Ace")
                        {
                                value[i] = 14;
                        }
                }
                return value;
        }
        
        public static int[] sortedValues(int [] sorted)
        {
                int temp;
                for(int i = 0; i<4; i++)
                {
                        if(sorted[i] > sorted[i+1])
                        {
                                temp = sorted[i];
                                sorted[i] = sorted[i+1];
                                sorted[i+1] = temp;
                        } 
                }
                return sorted;
        }
        
        public static boolean HighCard(int[] sortedCards)
        {
                boolean highCard = true;
                if((sortedCards[0] == sortedCards[1]) || (sortedCards[1] == sortedCards[2]) || (sortedCards[2] == sortedCards[3]) || (sortedCards[3] == sortedCards[4]))
                {
                        highCard = false;
                }
                if(highCard == true)
                        return true;
                else
                        return false;
        }
        
        public static boolean OnePair(int[] sortedCards)
        {
                int counter = 0;
                for(int i = 0; i<4; i++)
                {
                        for(int j = i+1; j<5; j++)
                        {
                                if(sortedCards[i] == sortedCards[j])
                                        counter++;
                        }
                }
                if(counter == 1)
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        
        public static boolean TwoPair(int[] sortedCards)
        {
                boolean twoPair = false;
                int counter = 0;
                for(int i = 0; i<4; i++)
                {
                        for(int j = i+1; j<5; j++)
                        {
                                if(sortedCards[i] == sortedCards[j])
                                        counter++;
                        }
                }
                if(counter == 2)
                {
                        if(sortedCards[0] == sortedCards[1] && sortedCards[2] == sortedCards[3])
                                twoPair = true;
                        else if(sortedCards[0] == sortedCards[1] && sortedCards[3] == sortedCards[4])
                                twoPair = true;
                        else if(sortedCards[1] == sortedCards[2] && sortedCards[3] == sortedCards[4])
                                twoPair = true;
                        
                }

                if(twoPair == true)
                        return true;
                else 
                        return false;
        }
        
        public static boolean threeOfAKind(int[] sortedCards)
        {
                boolean threeofakind = false;
                int counter = 0;
                for(int i = 0; i<4; i++)
                {
                        for(int j = i+1; j<5; j++)
                        {
                                if(sortedCards[i] == sortedCards[j])
                                        counter++;
                        }
                }
                if(counter == 2)
                {
                        if(sortedCards[0] == sortedCards[1] && sortedCards[1] == sortedCards[2])
                                threeofakind = true;
                        else if(sortedCards[1] == sortedCards[2] && sortedCards[2] == sortedCards[3])
                                threeofakind = true;
                        else if(sortedCards[2] == sortedCards[3] && sortedCards[3] == sortedCards[4])
                                threeofakind = true;
                }
                
                if(threeofakind == true)
                        return true;
                else 
                        return false;
        }
        
        public static boolean straight(int[] sortedCards)
        {
                boolean straight = false;
                if(sortedCards[0]+1 == sortedCards[1] && sortedCards[1]+1 == sortedCards[2] && sortedCards[2]+1 == sortedCards[3] && sortedCards[3]+1 == sortedCards[4])
                {
                        straight = true;
                }
                if(straight == true)
                        return true;
                else 
                        return false;
        }
        
        public static boolean Flush(Card[] Hand)
        {
                boolean flush = false;
                if(Hand[0].suit == Hand[1].suit && Hand[1].suit == Hand[2].suit && Hand[2].suit == Hand[3].suit && Hand[3].suit == Hand[4].suit)
                {
                        flush = true;
                }
                if(flush == true)
                        return true;
                else 
                        return false;
        }
        
        public static boolean FullHouse(int[] sortedCards)
        {
                boolean fullhouse = false;
                if(sortedCards[0] == sortedCards[1] && sortedCards[1] == sortedCards[2] && sortedCards[3] == sortedCards[4])
                {
                        fullhouse = true;
                }
                else if(sortedCards[0] == sortedCards[1] && sortedCards[2] == sortedCards[3] && sortedCards[3] == sortedCards[4])
                {
                        fullhouse = true;
                }
                if(fullhouse == true)
                        return true;
                else 
                        return false;
        }
        
        public static boolean fourOfAKind(int[] sortedCards)
        {
                boolean fourofakind = false;
                if(sortedCards[0] == sortedCards[1] && sortedCards[1] == sortedCards[2] && sortedCards[2] == sortedCards[3])
                        fourofakind = true;
                else if(sortedCards[1] == sortedCards[2] && sortedCards[2] == sortedCards[3] && sortedCards[3] == sortedCards[4])
                        fourofakind = true;
        
                if(fourofakind == true)
                        return true;
                else 
                        return false;
        }
        
        public static boolean straightFlush(int[] sortedCards, Card[] Hand)
        {
                boolean straight = false;
                boolean flush = false;
                if(Hand[0].suit == Hand[1].suit && Hand[1].suit == Hand[2].suit && Hand[2].suit == Hand[3].suit && Hand[3].suit == Hand[4].suit)
                {
                        flush = true;
                }
                if(sortedCards[0]+1 == sortedCards[1] && sortedCards[1]+1 == sortedCards[2] && sortedCards[2]+1 == sortedCards[3] && sortedCards[3]+1 == sortedCards[4])
                {
                        straight = true;
                }
                if(flush == true && straight == true)
                        return true;
                else 
                        return false;
        }
        
        
        public static int Uklady(Card[] PlayerHand)
        {
                int uklad = 0;
                int[] tab = new int[5];
  
                        tab = Scheme.getValue(PlayerHand);
                tab = Scheme.sortedValues(tab);
                if(Scheme.straightFlush(tab, PlayerHand) == true)
                {
                        uklad = 8;
                }
                else if(Scheme.fourOfAKind(tab) == true)
                {
                        uklad = 7;
                }
                else if(Scheme.FullHouse(tab) == true)
                {
                        uklad = 6;
                }
                else if(Scheme.Flush(PlayerHand) == true)
                {
                        uklad = 5;
                }
                else if(Scheme.straight(tab) == true)
                {
                        uklad = 4;
                }
                else if(Scheme.threeOfAKind(tab) == true)
                {
                        uklad = 3;
                }
                else if(Scheme.TwoPair(tab) == true)
                {
                        uklad = 2;
                }
                else if(Scheme.OnePair(tab) == true)
                {
                        uklad = 1;
                }
                else if(Scheme.HighCard(tab) == true)
                {
                        uklad = 0;
                }
                
            
                return uklad;
        }
        public static int compareCards(int uklad1, int uklad2, int uklad3, int uklad4)
        {
        	    int powerest = 0;
                int max = uklad1;
                if(max < uklad2)
                {
                	max = uklad2;
                	powerest = 1;
                }
                if(max < uklad3)
                {
                	max = uklad3;
                	powerest = 2;
                }
                if(max < uklad4)
                {
                	max = uklad4;
                	powerest = 3;
                }
                return powerest;
        }
}